home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / multi_jitter / test.c < prev   
Encoding:
C/C++ Source or Header  |  1995-02-06  |  1.8 KB  |  106 lines

  1. /* TEST FILE FOR kc.multi.c, NOT FOR BOOK */
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6.  
  7.  
  8.  
  9. typedef struct {
  10.     double x, y;
  11. } Point2;
  12.  
  13.  
  14.  
  15. int srandom(int seed);
  16.  
  17. void MultiJitter(Point2 points[], int m, int n);
  18.  
  19.  
  20.  
  21. main(int argc, char *argv[]) {
  22.  
  23.     Point2 *points;
  24.     int m, n, i, x, y;
  25.     int **counts, *x_bins, *y_bins;
  26.  
  27.     if (argc != 4) {
  28.     fprintf(stderr, "Usage: multi-jitter <m> <n> <seed>.\n");
  29.     exit(1);
  30.     }
  31.  
  32.     m = atoi(argv[1]);
  33.     n = atoi(argv[2]);
  34.     srandom(atoi(argv[3]));
  35.  
  36.     points = (Point2 *) malloc(m*n*sizeof(Point2));
  37.     counts = (int **) malloc(m*sizeof(int *));
  38.     for (i = 0; i < m; i++)
  39.     counts[i] = (int *) malloc(n*sizeof(int));
  40.     x_bins = (int *) malloc(m*n*sizeof(int));
  41.     y_bins = (int *) malloc(m*n*sizeof(int));
  42.  
  43.     MultiJitter(points, m, n);
  44.  
  45.     /*
  46.      * Test jittered condition
  47.      */
  48.  
  49.     for (x = 0; x < m; x++) {
  50.     for (y = 0; y < n; y++) {
  51.         counts[x][y] = 0;
  52.     }
  53.     }
  54.  
  55.     for (i = 0; i < m*n; i++) {
  56.     x = points[i].x / (1.0/m);
  57.     y = points[i].y / (1.0/n);
  58.     counts[x][y]++;
  59.     }
  60.  
  61.     for (x = 0; x < m; x++) {
  62.     for (y = 0; y < n; y++) {
  63.         if (counts[x][y] != 1) {
  64.         fprintf(stderr, "Jittered condition not satisfied.\n");
  65.         goto done1;
  66.         }
  67.     }
  68.     }
  69.     done1:;
  70.  
  71.     /*
  72.      * Test n-rooks condition
  73.      */
  74.  
  75.     for (x = 0; x < m*n; x++)
  76.     x_bins[x] = 0;
  77.     for (y = 0; y < m*n; y++)
  78.     y_bins[y] = 0;
  79.  
  80.     for (i = 0; i < m*n; i++) {
  81.     x = points[i].x / (1.0/(m*n));
  82.     y = points[i].y / (1.0/(m*n));
  83.     x_bins[x]++;
  84.     y_bins[y]++;
  85.     }
  86.  
  87.     for (x = 0; x < m*n; x++) {
  88.     if (x_bins[x] != 1) {
  89.         fprintf(stderr, "n-rooks condition not satisfied in x.\n");
  90.         goto done2;
  91.     }
  92.     }
  93.     done2:;
  94.  
  95.     for (y = 0; y < m*n; y++) {
  96.     if (y_bins[y] != 1) {
  97.         fprintf(stderr, "n-rooks condition not satisfied in y.\n");
  98.         goto done3;
  99.     }
  100.     }
  101.     done3:;
  102.  
  103.     for (i = 0; i < m*n; i++)
  104.     fprintf(stderr, "(%f, %f)\n", points[i].x, points[i].y);
  105. }
  106.